package dao;

import java.util.Collection;

import model.TrackBean;
import web.dao.Criteria;
import web.dao.GenericDao;
import web.model.UUID;

public class TrackDao extends GenericDao<TrackBean> {

	public TrackDao() {
		super();
	}

	public Collection<TrackBean> getTrackByAlbumId(UUID album) {
		Collection<TrackBean> result = findByProperty("album", album);
		return result;
	}

	public TrackBean getTrackByAlbumIdAndPosition(UUID album, String index) {
		Criteria[] criteria = new Criteria[2];
		criteria[0] = Criteria.equal("album", album);
		criteria[1] = Criteria.equal("index", index);
		Collection<TrackBean> result = findByCriteria(criteria);
		if (result.isEmpty()) {
			return null;
		} else {
			return result.iterator().next();
		}
	}

	@Override
	public TrackBean find(TrackBean track) {
		return getTrackByAlbumIdAndPosition(track.getAlbum(), track.getIndex().toString());
	}
}
